#-*-encoding=utf-8-*-
title=u"""出车单"""
description=u"""公司内部人员使用车辆申请单"""
displayed_columns=[]
facetag = u"""状态
- Booked
- Finished"""

fields=(
    SingleSelectField(
        description=u'车型号',
        title=u'车型号',
        vocabulary_exp=u'flowsettings["cars"]',
        limit=4,
        write_condition=u'',
        default_value_exp=u'""',
        name=u'type'
),
    DateField(
        minutestep=5,
        description=u'借车开始时间',
        title=u'开始时间',
        showtime=True,
        write_condition=u'',
        default_value_exp=u'datetime.datetime.today()',
        name=u'start'
),
    DateField(
        minutestep=5,
        description=u'借车结束时间',
        title=u'结束时间',
        showtime=True,
        write_condition=u'',
        default_value_exp=u'datetime.datetime.today()',
        name=u'end'
),
    TextLineField(
        description=u'借车人',
        title=u'借车人',
        validation_exp=u"not value and '借车人为空！'",
        write_condition=u'',
        size=18,
        default_value_exp=u'""',
        name=u'name'
),
    TextLineField(
        description=u'驾驶员',
        title=u'驾驶员',
        validation_exp=u"not value and '驾驶员为空！'",
        write_condition=u'',
        size=18,
        default_value_exp=u'""',
        name=u'driver'
),
    PersonSelectField(
        description=u'申请部门',
        title=u'申请部门',
        validation_exp=u'',
        multiple_selection=True,
        selectable_object='grouponly',
        write_condition=u'',
        default_value_exp=u'[]',
        name=u'dept'
),
    TextField(
        rows=5,
        description=u'备注',
        title=u'备注',
        cols=10,
        validation_exp=u'',
        write_condition=u'',
        default_value_exp=u'"请填写原因及路线"',
        name=u'remark'
),
    PersonSelectField(
        description=u'部门负责人审批',
        title=u'部门负责人',
        validation_exp=u'',
        multiple_selection=True,
        selectable_object='persongroup',
        write_condition=u'',
        default_value_exp=u'[]',
        name=u'deptManager'
),
    PersonSelectField(
        description=u'办公室主人审批',
        title=u'办公室主人',
        validation_exp=u'',
        multiple_selection=True,
        selectable_object='persongroup',
        write_condition=u'',
        default_value_exp=u'[]',
        name=u'director'
),)

fields_validation_script=ur"""# 检查开始结束时间
start = sheet['start']
end = sheet['end']
type = sheet['type']

if start >= end:
    return { 'start':'开始不能迟于结束时间',
             'end':'结束不能迟于开始时间',
            }

result = searchObjects(path=container,
object_provides=['zopen.flow.interfaces.IFlowSheet'],
                        subjects=(["Booked", type], 'allof'), start=(None, end),
                        end=(start, None))

for item in result:
    if item is not sheet:
        return { 'start':'没有空的车型',
             'end':'没有空的车型'
           }

return {}

"""
